<?php
    session_start();
header("Content-Type: text/html; charset=utf-8");
    if (isset($_SESSION['login']) && $_SESSION['login'] > 0) {
        # 如果存在登录记录则进入后台。注意：因为Cookie被微信禁用，导致$_SESSION，所以用微信登录是无法打开后台的。
        
    }else {
        # 使用脚本重定向回到登录界面
        $url="login.php";
        echo "<script language=\"javascript\">";
        echo "location.href=\"$url\"";
        echo "</script>";
        exit();
    }

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "saylovewall";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT id ,nickName,mtime, toWho, contents FROM saylove_2017_posts WHERE isdisplay='0' order by id desc";
$result = $conn->query($sql);
$ccc=0;
if ($result->num_rows > 0) {
    // 输出数据
    while($row = $result->fetch_assoc()) {
		$ccc=$ccc+1;
               echo "<table border='1'>";
        echo "<tr>";
        echo "<td  width='80'>用户id" . " </td>";
        echo "<td>" . $row["id"] . "<a style='color: white; background-color:red;display: inline-block;padding: 2px;' href='./admin.php?id=".$row["id"]."'>禁用</a> </td>";
        echo "</tr><tr>";
        echo "<td  width='80'>昵称" . " </td>";
        echo "<td>". $row["nickName"] ."-(".$row["mtime"].")</td>";
        echo "</tr><tr>";
        echo "<td  width='80'>表白对象" . " </td>";
        echo "<td>". $row["toWho"] ."</td>";
        echo "</tr><tr>";
        echo "<td  width='80'>表白内容" . " </td>";
        echo "<td>". $row["contents"] . "</td>";
        echo "</tr>";
        echo "</table><br>";
    }
} else {
    echo "0 结果";
}
echo "共".$ccc."条记录";
$conn->close();



?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表白墙后台管理</title>
</head>
<body>

</body>
</html>